/********************************************************************
	copyright (c) by TwT
    @created:	11/15/2011   20:02
    @filename: 	mainFrame
    @author:	Gu Yanbo (gybgdhb@gmail.com)
    @brief:	    
*********************************************************************/

#ifndef _MAINFRAME_H_
#define _MAINFRAME_H_
#include "Gut.h"
#include "render_dx9.h"
#include "render_dx10.h"
#include "render_opengl.h"
#include "Configure.h"
#include "GetUserInput.h"
#include <stdio.h>
#include <conio.h>
#include "GameScene.h"

#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#pragma comment(lib,"glib.lib")


int main(int argc,char*argv[])
{
	Configure::FrameConfigure::SetObj(new Configure::FrameConfigure());
	int width,height;
	char* device;
	device=Configure::GetFrameConfigure()->GetDevice();
	width=Configure::GetFrameConfigure()->GetW();
	height=Configure::GetFrameConfigure()->GetH();
	bool (*release)()=ReleaseResourceDX9;
	bool (*init_resource)()=InitResourceDX9;
	void (*begin_render)()=BeginRenderDX9;
	void (*end_render)()=EndRenderDX9;
	puts(device);	
	GutCreateWindow(100,100,width,height,device);
	GutInputInit();

	if (!GutInitGraphicsDevice(device))
	{
		printf("Failed to initialize %s device",device);
		return -1;
	}
	if ( !init_resource() )
	{
		release();
		printf("Failed to load resources\n");
		exit(0);
	}
	GameScene gs;
	g_Timer.Start();
	while( GutProcessMessage() )
	{
		//render();
			GetUserInput();
			begin_render();
			gs.update();
			end_render();
		
	}
	g_Timer.Stop();
	GutReleaseGraphicsDevice();
	GutInputClose();
	//system("pause");
	return 0;
}

#endif //_MAINFRAME_H_

//
//History:
//[11/15/2011] <gybgdhb@gmail.com> created